package com.music.service.impl;

import com.music.dao.AlbumMapper;
import com.music.dao.MvMapper;
import com.music.dao.SongListMapper;
import com.music.dao.SongMapper;
import com.music.entity.*;
import com.music.service.CountService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.ArrayList;
import java.util.List;
@Service
public class CountServiceImpl implements CountService {
    @Autowired
    private SongListMapper songListMapper;
    @Autowired
    private SongMapper songMapper;
    @Autowired
    private AlbumMapper albumMapper;
    @Autowired
    private MvMapper mvMapper;
    @Override
    public List<UserLikeVo> songListCount() {
        List<SongList> list=songListMapper.findCount();
        List<UserLikeVo> list1=new ArrayList<UserLikeVo>();
        if(!list.isEmpty()){
            for(int i=0;i<list.size();i++){
                UserLikeVo userLikeVo=new UserLikeVo();
                userLikeVo.setObjName(list.get(i).getSongListName());
                userLikeVo.setCount(Integer.valueOf(list.get(i).getSongListPlayCount()));
                list1.add(userLikeVo);
            }
        }
        return list1;
    }

    @Override
    public List<UserLikeVo> songCount() {
        List<Song> list=songMapper.findSongCount();
        List<UserLikeVo> list1=new ArrayList<UserLikeVo>();
        if(!list.isEmpty()){
            for(int i=0;i<list.size();i++){
                UserLikeVo userLikeVo=new UserLikeVo();
                userLikeVo.setObjName(list.get(i).getSongName());
                userLikeVo.setCount(list.get(i).getSongPlayCount());
                list1.add(userLikeVo);
            }
        }
        return list1;
    }

    @Override
    public List<UserLikeVo> albumCount() {
        List<Album> list=albumMapper.findAlbumCount();
        List<UserLikeVo> list1=new ArrayList<UserLikeVo>();
        if(!list.isEmpty()){
            for(int i=0;i<list.size();i++){
                UserLikeVo userLikeVo=new UserLikeVo();
                userLikeVo.setObjName(list.get(i).getAlbumName());
                userLikeVo.setCount(list.get(i).getAlbumPurchases());
                list1.add(userLikeVo);
            }
        }
        return list1;
    }

    @Override
    public List<UserLikeVo> mvCount() {
        List<Mv> list=mvMapper.findMvCount();
        List<UserLikeVo> list1=new ArrayList<UserLikeVo>();
        if(!list.isEmpty()){
            for(int i=0;i<list.size();i++){
                UserLikeVo userLikeVo=new UserLikeVo();
                userLikeVo.setObjName(list.get(i).getMvName());
                userLikeVo.setCount(Integer.valueOf(list.get(i).getMvClick()));
                list1.add(userLikeVo);
            }
        }
        return list1;
    }
}
